<template>
  <div class="orderTableList">
    <!-- 列表查询 -->
    <UserSearch @search="reload"></UserSearch>
    <el-card class="box-card"
             shadow="never">
      <ele-pro-table ref="table"
                     :columns="columns"
                     :datasource="datasource"
                     :selection.sync="selection"
                     :disabled="false"
                     cache-key="systemUserTable">
        <!-- 表头工具栏 -->
        <template v-slot:toolbar>
          <el-button size="small"
                     type="danger"
                     icon="el-icon-delete"
                     class="ele-btn-icon"
                     @click="removeBatch">
            批量删除
          </el-button>
        </template>
        <!-- 名称 -->
        <template v-slot:realName="{ row }">
          <div class="realNameStyle flex">
            <img class="avaterName"
                 :src="row.avatar"
                 alt="" />
            <div class="flex-column-start">
              <div style="width: 40px">{{ row.nickname }}</div>
            </div>
          </div>
        </template>

        <!-- <template v-slot:realName="{ row }">
          <div class="realNameStyle flex-start">
            <img class="avaterName"
                 :src="row.avatar"
                 alt="" />
            <div class="flex-columns-center">
              <div>{{ row.nickname }}</div>

            </div>
          </div>
        </template> -->
        <!-- 收款账号 -->
        <template v-slot:enabledNot="{ row }">
          <el-tag :type="enabledNotType(row.enabledNot).type">
            {{ enabledNotType(row.enabledNot).status }}
          </el-tag>
        </template>
        <!-- 体现类型 -->
        <template v-slot:withdrawAccount="{ row }">
          <div>{{ row.withdrawAccount ? row.withdrawAccount : '-- --' }}</div>
        </template>
        <!-- 当前状态 -->
        <template v-slot:status="{ row }">
          <el-tag :type="currentStateType(row.status).type">
            {{ currentStateType(row.status).status }}
          </el-tag>
        </template>

        <!-- 操作 -->
        <template v-slot:action="{ row }">
          <el-link v-if="row.status == 1"
                   type="primary"
                   :underline="false"
                   icon="el-icon-document"
                   @click="viewDetail(row)">
            提现审核
          </el-link>
          <el-link v-if="row.status == 3"
                   type="danger"
                   :underline="false"
                   icon="el-icon-document-delete"
                   @click="viewDetail(row)">
            驳回原因
          </el-link>
          <el-popconfirm class="ele-action"
                         title="是否确定要删除该信息"
                         @confirm="remove(row)">
            <template v-slot:reference>
              <el-link type="danger"
                       icon="el-icon-delete"
                       :underline="false">
                删除
              </el-link>
            </template>
          </el-popconfirm>
        </template>
      </ele-pro-table>
    </el-card>
    <!-- 体现审核 -->
    <drawerReflect :data="current"
                   :drawerReflectBoolen.sync="drawerReflectBoolen"
                   @done="reload"></drawerReflect>
  </div>
</template>
<script>
import UserSearch from './user-search.vue';
import { withdrawalList, technicianWithdrawalDelete, technicianWithdrawalBatch } from '@/api/withdrawalManagement/withdrawalList/index';
import drawerReflect from '../components/drawerReflect.vue';
import { reflectTableList } from '../constant/constant';

export default {
  name: 'reflectList',
  components: {
    drawerReflect,
    UserSearch
  },
  data () {
    return {
      reflectTableList,
      //  技能评分
      colors: ['#99A9BF', '#F7BA2A', '#FF9900'],
      value: 4,
      // 表格列配置
      columns: [
        {
          columnKey: 'selection',
          type: 'selection',
          width: 45,
          align: 'center',
          fixed: 'left'
        },
        {
          prop: 'realName',
          label: '申请人',
          sortable: 'custom',

          showOverflowTooltip: true,
          minWidth: 160,
          slot: 'realName'
        },
        {
          prop: 'withdrawActualAmount',
          label: '提现实际金额',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'applicationsAmount'
        },
        {
          prop: 'withdrawAmount',
          label: '提现金额',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'applicationsAmount'
        },
        {
          prop: 'withdrawOrderNumber',
          label: '提现订单编号',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'withdrawOrderNumber'
        },
        {
          prop: 'enabledNot',
          label: '提现方式',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'enabledNot'
        },

        {
          prop: 'withdrawAccount',
          label: '收款账号',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 150,
          slot: 'withdrawAccount'
        },
        {
          prop: 'status',
          label: '当前状态',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'status'
        },
        {
          prop: 'serviceCharge',
          label: '手续费',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110
        },

        {
          prop: 'createdAt',
          label: '申请时间',
          sortable: 'custom',
          align: 'center',
          showOverflowTooltip: true,
          minWidth: 110,
          slot: 'createdAt',
          formatter: (_row, _column, cellValue) => {
            return this.$util.toDateString(cellValue, 'yyyy-MM-dd HH:mm');
          }
        },
        {
          columnKey: 'action',
          label: '操作',
          width: 220,
          align: 'center',
          resizable: false,
          slot: 'action',
          showOverflowTooltip: true,

          fixed: 'right'
        }
      ],
      current: null,
      // 表格选中数据
      selection: [],
      drawerReflectBoolen: false
    };
  },
  computed: {
    // 是否开启响应式布局
    styleResponsive () {
      return this.$store.state.theme.styleResponsive;
    },
    // 服务状态
    currentStateType () {
      return function (currentStateType) {
        // console.log(applyType)
        if (currentStateType == '1') {
          return {
            status: '提现中',
            type: 'success'
          };
        } else if (currentStateType == '2') {
          return {
            status: '提现完成',
            type: ''
          };
        } else if (currentStateType == '3') {
          return {
            status: '已驳回',
            type: 'danger'
          };
        }
      };
    },
    // 实名认证
    enabledNotType () {
      return function (reflectionType) {
        if (reflectionType == '1') {
          return {
            status: '支付宝',
            type: ''
          };
        } else {
          return {
            status: '微信',
            type: 'success'
          };
        }
      };
    }
  },
  activated () {
    this.reload()
  },
  methods: {
    // 点击查看详情弹出详情抽屉
    viewDetail (row) {
      console.log(row);

      if (row) {
        this.current = row;
        // 用户余额管理
        this.drawerReflectBoolen = !this.drawerReflectBoolen;
      }
    },

    /* 表格数据源 */
    datasource ({ page, limit, where, order }) {
      return withdrawalList({
        page,
        limit,
        ...where,
        siteId: this.$store.state.site.info.id
      });
    },
    /* 刷新表格 */
    reload (where) {
      this.$refs.table.reload({ page: 1, where: where, types: 1 });
    },

    /* 删除 */
    remove (row) {
      const loading = this.$loading({ lock: true });
      technicianWithdrawalDelete(row.id)
        .then((msg) => {
          loading.close();
          this.$message.success(msg);
          this.reload();
        })
        .catch((e) => {
          loading.close();
          this.$message.error(e.message);
        });
    },
    /* 批量删除 */
    removeBatch () {
      if (!this.selection.length) {
        this.$message.error('请至少选择一条数据');
        return;
      }
      console.log(this.selection);
      this.$confirm('确定要删除选中的信息吗?', '提示', {
        type: 'warning'
      })
        .then(() => {
          const loading = this.$loading({ lock: true });
          console.log(this.selection.map((d) => d.id));
          technicianWithdrawalBatch(this.selection.map((d) => d.id))
            .then((msg) => {
              loading.close();
              this.$message.success(msg);
              this.reload();
            })
            .catch((e) => {
              loading.close();
              this.$message.error(e.message);
            });
        })
        .catch(() => { });
    }
  }
};
</script>
<style lang="less" scoped>
/deep/ .el-textarea__inner {
  height: 100px;
}
.orderTableList {
  .realNameStyle {
    .avaterName {
      width: 41px;
      height: 41px;
      border-radius: 36px;
      vertical-align: middle;
      margin-right: 5px;
    }
    .technicianName {
      color: #1890ff;
      font-size: 12px;
      font-style: normal;
      font-weight: 400;
    }
  }
  .orderrowinfo {
    width: 100%;
    display: flex;
    margin-left: 15px;
    padding: 30px;
    height: 50px;
    align-items: center;
    background-color: #f8f8f8;
    .orderNumber,
    .createDate,
    .buyName,
    .iphone {
      margin-right: 40px;
      color: #000;
      font-family: Inter;
      font-size: 14px;
      font-style: normal;
      font-weight: 400;
    }
  }
}
</style>
